package com.web.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.web.model.BookInfo;
import com.web.repository.BookRepository;

@Service("bookService")
public class BookServiceImpl implements BookService {

	@Autowired
	private BookRepository bookRepository;
	
	public List<BookInfo> findBooks(BookInfo bookInfo) {
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("isBook", bookInfo.getIsBook());
		if (StringUtils.isNotBlank(bookInfo.getBookName())) {
			params.put("bookName", bookInfo.getBookName());
		}
		if (bookInfo.getBookId() != null) {
			params.put("bookId", bookInfo.getBookId());
		}
		if (bookInfo.getStart() != null) {
			params.put("start", bookInfo.getStart());
		}
		if (bookInfo.getLimit() != null) {
			params.put("limit", bookInfo.getLimit());
		}
		if (StringUtils.isNotBlank(bookInfo.getTagnames())) {
			params.put("tagnames", bookInfo.getTagnames());
		}
		List<BookInfo> books = bookRepository.findBooks(params);
		return books;
	}

}
